$(function (){
	layui.use(["upload","form","element"],function(){
	/* 	var upload=layui.upload;
		upload.render({
			elem:"#upload",
			url:"" 
			})*/
			var form = layui.form;
			
			//注意：导航 依赖 element 模块，否则无法进行功能性操作
			var element = layui.element;
			var upload=layui.upload;
			var uploadInst=upload.render({
				elem:"#upload",
				url:"http://httpbin.org/post",
				before:function (obj) {
					obj.preview(function(index,file,result){
						$("#showImg").attr('src',result);
						console.log(result.url)
					});
					
				},
				done:function(res){
					console.log(res)
					if(res.code>0){
						return layui.msg(上传失败)
					}
				}
			})
		//监听提交
		form.on('submit', function(data) {
			console.log("=========")
			var message=JSON.stringify(data.field)
			layer.msg(message);
			console.log(layer.msg(JSON.stringify(data.field)))
			console.log(JSON.stringify(data.field))
			console.log(data.phone)
				$.ajax({
					// type: "post",
					dataType: "JSON",
					// url: "/user/my_message", //url
					// data: $('#popupForm').serialize(), //表单数据
					data:message,
					success: function(result) {
						if (result = "seccess") {
							layer.msg('修改成功，3秒后自动关闭该窗口');
							//延迟1秒执行，目的是让用户看到提示
							setTimeout(function() {
								//1、先得到当前iframe层（弹出层）的索引  ///2、提交成功关闭弹出层窗口
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							}, 1 * 3000);
						};
					},
					error: function() {
						layer.msg('后台异常！修改失败');
					}
				});
				return false;
		});
	})
})